//
//  assignment_operator.cpp
//  learnC++
//
//  Created by liuzhibing on 2018/6/7.
//  Copyright © 2018年 yunfan.com. All rights reserved.
//

#include "assignment_operator.hpp"
std::ostream& operator<<(std::ostream& out, const MyString2 &s)
{
    out << s.m_data;
    return out;
}

MyString2 & MyString2::operator=(const MyString2 &str){
    
    if (this == &str) {
        //防止自己复制自己
        return *this;
    }
    
    if (m_data) {
        delete[] m_data;
    }
    m_length = str.m_length;
    m_data = new char[m_length];
    
    for (int i = 0; i < m_length; ++i) {
        m_data[i] = str.m_data[i];
    }
    return *this;
}
